import cv2
import time

cap = cv2.VideoCapture(1)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))  # 必须设为MJPG格式以支持高帧率[5](@ref)
cap.set(cv2.CAP_PROP_FPS, 150)  # 尝试设置目标帧率

start = time.time()
frame_count = 0
while frame_count < 100:  # 测试100帧
    ret, frame = cap.read()
    #cv2.imshow("frame", frame)
    #cv2.waitKey(1)
    frame_count += 1
    print(frame_count)
fps = frame_count / (time.time() - start)
print(f"实际帧率: {fps:.2f} FPS")